<include file="public@header"/>

<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('StudentScore/index')}">学生成绩列表</a></li>
        <li><a href="{:url('StudentScore/add', ['is_teacher'=>$is_teacher])}">添加</a></li>
    </ul>
    <form class="well form-inline margin-top-20 row" method="post" action="{:url('StudentScore/index')}">
        <label class="form-group col-md-6 col-xs-12" style="margin-bottom: 15px;">
            学校-班级:
            <select class="form-control" name="school_id" id="school_id" style="width:179px;">
                <option value='0'>全部</option>
                <notempty name="schools">
                    <volist name="schools" id="vo">
                        <if condition="isset($param.school_id) && $param.school_id == $vo.id">
                            <option value="{$vo.id}" selected>{$vo.name}</option>
                        <else/>
                            <option value="{$vo.id}">{$vo.name}</option>
                        </if>
                    </volist>
                </notempty>
            </select> -
            <select class="form-control" name="class_id" id="class_id" style="width:179px;">
                <option value='0'>全部</option>
                <notempty name="classes">
                    <volist name="classes" id="vo">
                        <if condition="isset($param.class_id) && $param.class_id == $vo.id">
                            <option value="{$vo.id}" selected>{$vo.name}</option>
                            <else/>
                            <option value="{$vo.id}">{$vo.name}</option>
                        </if>
                    </volist>
                </notempty>
            </select>
        </label>

        <label class="form-group col-md-6 col-xs-6" style="margin-bottom: 15px;" >
            课程:
            <select class="form-control" name="course_id" id="course_id" >
                <option value='0'>全部</option>
                <notempty name="courses">
                    <volist name="courses" id="vo">
                        <if condition="isset($param.course_id) && $param.course_id == $vo.id">
                            <option value="{$vo.id}" selected>{$vo.course_name}</option>
                            <else/>
                            <option value="{$vo.id}">{$vo.course_name}</option>
                        </if>
                    </volist>
                </notempty>
            </select>
        </label>

        <label class="form-group col-md-6 col-xs-12" >
            <span>
                <span style="margin-right: 20px;">最高分：{:number_format($show_score.max_score,2)}</span>
                <span style="margin-right: 20px;">最低分：{:number_format($show_score.min_score,2)}</span>
                <span style="margin-right: 20px;">平均分：{:number_format($show_score.average_score,2)}</span>
            </span>
        </label>

        <label class="form-group col-md-6 col-xs-6">
            <input type="submit" class="btn btn-primary" value="搜索"/>
            <a class="btn btn-danger" href="{:url('StudentScore/index')}">清空</a>
        </label>
    </form>

    <form class="col-xs-4 col-md-1 form-group" style="float:right; margin-top:-75px;"
          method="post" action="{:url('StudentScore/exportExcel')}">
        <label>
            <input type="hidden" name="school" id="export_school" value="0">
            <input type="hidden" name="class" id="export_class" value="0">
            <input type="hidden" name="course" id="export_course" value="0">

            <button type="submit" class="btn btn-primary" onclick="exportExcel()" title="根据筛选条件导出表格">导出</button>
            {$arr_error|default=''}
        </label>
    </form>

    <form class="js-ajax-form" action="" method="post">
        <div class="table-actions">
            <button class="btn btn-danger btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('StudentScore/delete')}" data-subcheck="true" data-msg="您确定删除吗？">批量删除
            </button>
            <a id="scholarship" class="btn btn-primary btn-sm">发放奖学金</a>
        </div>
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="15">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <!--<th>编号</th>-->
                <th>学号</th>
                <th>学生</th>
                <th>学校</th>
                <th>班级</th>
                <th>年级</th>
                <th>课程</th>
                <th>第一题</th>
                <th>第二题</th>
                <th>第三题</th>
                <th>第四题</th>
                <th>第五题</th>
                <th>第六题</th>
                <th>附加分</th>
                <th>总分</th>
                <th>奖学金(元)</th>
                <th>奖学金有效期</th>
                <th>操作</th>
            </tr>
            </thead>
            <notempty name="score">
                <foreach name="score" item="vo">
                    <tr>
                        <td>
                            <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                                   value="{$vo.id}" title="ID:{$vo.id}">
                        </td>
                        <!--<td>{$vo.id}</td>-->
                        <td>{$vo.code}</td>
                        <td>{$vo.student_name}</td>
                        <td>{$vo.school_name}</td>
                        <td>{$vo.class_name}</td>
                        <td>
                            <if condition="$vo.grade eq 1">
                                一年级
                            <elseif condition="$vo.grade eq 2"/>
                                二年级
                            <elseif  condition="$vo.grade eq 3"/>
                                三年级
                            <elseif  condition="$vo.grade eq 4"/>
                                四年级
                            <elseif  condition="$vo.grade eq 5"/>
                                五年级
                            <elseif  condition="$vo.grade eq 6"/>
                                六年级
                            <elseif  condition="$vo.grade eq 7"/>
                                七年级
                            <elseif  condition="$vo.grade eq 8"/>
                                八年级
                            <elseif  condition="$vo.grade eq 9"/>
                                九年级
                            <elseif  condition="$vo.grade eq 10"/>
                                高一
                            <elseif  condition="$vo.grade eq 11"/>
                                高二
                            <else/>
                                高三
                            </if>
                        </td>
                        <td>{$vo.course_name}</td>
                        <td>{$vo.question1}</td>
                        <td>{$vo.question2}</td>
                        <td>{$vo.question3}</td>
                        <td>{$vo.question4}</td>
                        <td>{$vo.question5}</td>
                        <td>{$vo.question6}</td>
                        <td>{$vo.extra_score}</td>
                        <td>{$vo.total_score}</td>
                        <td>
                            <if condition="isset($vo.award_money)">
                                {$vo.award_money}
                            </if>
                        </td>
                        <td>
                            <if condition="isset($vo.award_money) && isset($vo.valid_date) && $vo.valid_date gt 0">
                                {:date('Y-m-d',$vo.valid_date)}
                            </if>
                        </td>
                        <td>
                            <a href="{:url('StudentScore/edit',array('id'=>$vo['id'],'is_teacher'=>$is_teacher))}">{:lang('EDIT')}</a> |
                            <a href="{:url('StudentScore/delete',array('id'=>$vo['id']))}" class="js-ajax-delete">{:lang('DELETE')}</a>
                        </td>
                    </tr>
                </foreach>
            </notempty>
        </table>
        <div class="pagination">{$page|default=''}</div>
    </form>
</div>

<div class="setScholarship" style="display: none;">
    <form class="well row  js-ajax-form"  style="margin:0;" action="{:url('StudentScore/scholarship')}" method="post">
        <input type="hidden" name="score_ids" >
        <label for="金额">
            请输入发放的奖学金金额:
            <input class="form-control" type="number"  name="award_money" min="0" value="">
        </label>
        <button type="submit" class="js-ajax-submit" id="submitScholarship" style="display: none;"></button>
    </form>
</div>


<script src="__STATIC__/js/admin.js"></script>
<script>

    $(document).ready(function () {
        $('#school_id').on('change',function () {
            var sid = $(this).val();
            if(sid == 0){
                $('#class_id').empty();
                var html = '<option value=\"0\">全部</option>';
                $('#class_id').html(html);
                return false;
            }
            $.ajax({
                url:"{:url('StudentScore/ajaxClass')}",
                type:'post',
                dataType:'json',
                data:{"school_id":sid},
                success:function(jsonData){
                    $('#class_id').empty();
                    var html = '<option value=\"0\">全部</option>';

                    if(jsonData.code == 1){
                        for(var i in jsonData.data){
                            html += '<option value=\"'+jsonData.data[i].id+'\">'+jsonData.data[i].name+'</option>';
                        }
                    }
                    $('#class_id').html(html);
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    console.log('xhr='+XMLHttpRequest.readyState+' status='+textStatus+' error='+errorThrown);
                }
            });
        });
//        $('input[name="start"]').datepicker();
//        $('input[name="end"]').datepicker();

    });

    //导出
    function exportExcel() {
        var schoolId = $('#school_id').val();
        var classId = $('#class_id').val();
        var courseId = $('#course_id').val();

        $('#export_school').val(schoolId);
        $('#export_class').val(classId);
        $('#export_course').val(courseId);
    }

    $('body').on('click','#scholarship',function () {
        var arrId=[];
        $('.js-check-all').attr('checked',false);
        $(':checkbox:checked').each(function () {
            arrId.push($(this).attr('title').split(':')[1]);
        });

        $('[name=score_ids]').val(arrId);

        layer.open({
            type: 1,
            btn: ['提交'],
            title: '发放奖学金',
            content: $('.setScholarship'),
            yes: function (index,layero)
            {
                $('#submitScholarship').click();
                layer.close(index);
            }
        })
    })
</script>
</body>